package com.yanqu.road.server.cmd.player;

import com.alibaba.fastjson.JSONObject;
import com.yanqu.road.entity.player.DestroyRoleInfo;
import com.yanqu.road.entity.player.UserWechatBind;
import com.yanqu.road.logic.config.ChannelConfig;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.common.ConfigProto;
import com.yanqu.road.server.GameServer;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.minibind.WechatBindModule;
import com.yanqu.road.server.helper.SignHelper;
import com.yanqu.road.server.manger.config.WechatBindMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.MD5Security;
import com.yanqu.road.utils.date.DateHelper;
import com.yanqu.road.utils.http.HttpHelper;
import com.yanqu.road.utils.string.StringUtils;

import java.net.URLDecoder;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;

@Cmd(code = Protocol.S_WECHAT_BIND_ROLE_INFO, desc = "小程序绑定角色信息")
public class GetWechatBindRoleInfoCmd extends AbstractCommand {
    private DestroyRoleInfo destroyRoleInfo = null;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        int code = 1;
        UserWechatBind userData = player.getModule(WechatBindModule.class).getUserData();
        if (userData == null) {
            ret = GameErrorCode.E_WX_BIND_NOT_GAME_ID;
            return;
        }
        WechatBindMgr.addUrlQueryTask(Protocol.S_WECHAT_BIND_ROLE_INFO, player);
//        if (userData.isBind()) {
//            code = 2;
//        } else {
//            WechatBindMgr.addUrlQueryTask(Protocol.S_WECHAT_BIND_ROLE_INFO, player);
//            return;
//        }
//
//        ConfigProto.WechatBindRoleInfoRespMsg.Builder respMsg = ConfigProto.WechatBindRoleInfoRespMsg.newBuilder();
//        respMsg.setRet(0);
//        respMsg.setCode(code);
//        respMsg.setExpository(ChannelConfig.WX_BIND_EXPOSITORY);
//
//        player.sendPacket(ClientProtocol.U_WECHAT_BIND_ROLE_INFO, respMsg);

    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret > 0) {
            player.sendPacket(ClientProtocol.U_WECHAT_BIND_ROLE_INFO, ConfigProto.WechatBindRoleInfoRespMsg.newBuilder().setRet(ret));
        }
    }
}
